import axios from "../axios";


//对象数据剪切成字符串
const getData = (obj) => {
    let arr = []
    for (const key in obj) {
        arr.push(key + "=" + obj[key])
    }
    return arr.join("&")
}
//token
const token = localStorage.getItem("token") ? localStorage.getItem("token") : ''

//登录
export const userLogin = (item) => {
    return axios.post("/admin/login", getData(item))
}

//请求轮播图
export const bannerList = () => {
    return axios.get("/banner/list", {
        headers: {
            token
        }
    })
}

//插入轮播图
export const addBanner = (item) => {
    return axios.post("/banner/add", getData(item), {
        headers: {
            token
        }
    })
}

//删除单个轮播图
export const deleteBanner = (id) => {
    return axios.get("/banner/delete?bannerid=" + id, {
        headers: {
            token
        }
    })
}
//商品列表
export const proList = () => {
    return axios.get("/pro/list", {
        headers: {
            token
        }
    })
}
//商品分类
export const getCategory = () => {
    return axios.get("/pro/getCategory", {
        headers: {
            token
        }
    })

}
//用户列表
export const userList = () => {
    return axios.get("/user/list", {
        headers: {
            token
        }
    })
}
//管理员列表
export const adminList = () => {
    return axios.get("/admin/list", {
        headers: {
            token
        }
    })
}
//修改管理员信息
export const editAdminList = (item) => {
    return axios.post("/admin/update", getData(item), {
        headers: {
            token
        }
    })
}

//删除管理员信息
export const deleteAdmin = (id) => {
    return axios.post("/admin/delete", getData(id), {
        headers: {
            token
        }
    })
}

//添加管理员
export const addAdminList = (item) => {
    return axios.post("/admin/add", getData(item), {
        headers: {
            token
        }
    })
}
//获取管理员信息
export const adminDetail = (item) => {
    return axios.get("/admin/detail?adminname=" + item, {
        headers: {
            token
        }
    })
}
//订单列表
export const orderFromList = () => {
    return axios.get("/order/list", {
        headers: {
            token
        }
    })
}
//修改订单状态
export const updateStatus = (item) => {
    return axios.post("/order/updateStatus", getData(item), {
        headers: {
            token
        }
    })
}
//购物车列表
export const cartList = () => {
    return axios.get("/cart/list2", {
        headers: {
            token
        }
    })
}
//折线图
export const echartsLine = () => {
    return axios.get("/data/kData", {
        headers: {
            token
        }
    })
}
//饼图
export const echartsPie = () => {
    return axios.get("/data/simpleData", {
        headers: {
            token
        }
    })
}
//商品总数量
export const statProduct = () => {
    return axios.get("/statistic/product", {
        headers: {
            token
        }
    })
}
//用户总数量
export const statUser = () => {
    return axios.get("/statistic/user", {
        headers: {
            token
        }
    })
}